package org.web.base.domain;

import com.google.gson.Gson;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * 用于定义保留字段。
 */
public class UpdateComments {

    private static Gson gson = new Gson();
    private int maxNum = 5;

    private List<UpdateRecord> list;

    public String getComments() {
        return gson.toJson(list);
    }

    public void setComments(String json) {
        this.list = gson.fromJson(json, List.class);
    }

    public static void main(String[] args) {
        UpdateComments updateComments = new UpdateComments();

        List<UpdateRecord> list = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            UpdateRecord updateRecord = new UpdateRecord();
            list.add(updateRecord);
            updateRecord.setComments("update");
            updateRecord.setOldRecord("system");
            updateRecord.setOldRecord("fff");
        }

        String value = gson.toJson(list);
        updateComments.setComments(value);
        System.out.println(updateComments.getComments());
        System.out.println();
    }
}

@Setter
@Getter
class UpdateRecord {
    /**
     * 记录变更的操作人员
     */
    private String operatorName = "system";

    /**
     * 记录变更的原因
     */
    private String comments = "update";

    /**
     * 记录变更前的内容
     */
    private String oldRecord = "";


}


